package com.xplay.xpocker.room;

import com.xplay.xpocker.room.message.MessageContent;
import com.xplay.xpocker.util.JacksonStringUtil;
import lombok.Data;

@Data
public class Message {
    // 消息主体
    public MessageContent message;
    // 是否产生延迟
    public double delay;

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer("\n");
        sb.append("===================start===================\n");
        sb.append("房间号:");
        sb.append(message.getRoomCode());
        sb.append("\n");

        sb.append("房间版本:");
        sb.append(message.getSyncVersion());
        sb.append("\n");

        sb.append("发送类型:");
        sb.append(message.getMnEnum());
        sb.append("\n");

        sb.append("事件触发人:");
        sb.append(message.getMessageFromUid());
        sb.append("\n");

        sb.append("指定消息人:");
        sb.append(message.getMessageToUid());
        sb.append("\n");

        sb.append("延迟时间:");
        sb.append(this.delay);
        sb.append("/ms");
        sb.append("\n");

        sb.append("消息主体:");
        sb.append(JacksonStringUtil.objectToString(message.getBody(), false));
        sb.append("\n");

        sb.append("===================end===================");
        return sb.toString();
    }

    public static class MessageBuilder {
        private Message messageToClient;

        private MessageBuilder(Message messageToClient) {
            this.messageToClient = messageToClient;
        }

        public static MessageBuilder init() {
            return new MessageBuilder(new Message());
        }

        public MessageBuilder setMessage(MessageContent message) {
            this.messageToClient.setMessage(message);
            return this;
        }

        public MessageBuilder setDelay(double setDelay) {
            this.messageToClient.setDelay(setDelay);
            return this;
        }

        public Message builder() {
            return this.messageToClient;
        }

    }
}
